﻿// JScript 文件
document.oncontextmenu=function(e){return false;} 
var vList = new CtnListCtrl("vList");
var Menu = new CtnMenuCtrl("Menu");
vList.create("result");

vList.pagesize = 10;
vList.onGoPage = gotoPage;
vList.onRowClick  = onRowClick;
vList.onRowRClick  = onRowClick;


var strsql = null;
var major = 0;
var minor = 0;
var id0 = null;
var addrid0 = null;

function InitDzxq()
{
    var allinput = document.getElementsByTagName("input");
    var allselect = document.getElementsByTagName("select");
    for(var i = 0;i<allinput.length;i++)
    {
        if(allinput[i].type != "checkbox" && allinput[i].type != "button")
        {
            allinput[i].disabled = true;
            allinput[i].style.backgroundColor = "#F5F5F5"
        }
    }
    for(i = 0;i<allselect.length;i++)
    {
        allselect[i].disabled = true;
        allselect[i].style.backgroundColor = "#F5F5F5"
    }
    
    $("result").oncontextmenu  = function (evt)
    
    { 
        Menu.clear();
        with(Menu)
            {            
                addEvent("浏览属性","AttView()");
                addEvent("地址定位", "AddrLoct()");         
            } 
        Menu.show(evt);
        return false;
    }
}

function Resetcheck(ID,obj) 
{
    if(ID.checked)
    {
        if(obj == "Select_jb")
        {
            $(obj).disabled = false
            $(obj).style.backgroundColor = "#FFFFFF"
            $("Text_jb").disabled = false
            $("Text_jb").style.backgroundColor = "#FFFFFF"   
            $("button_query").disabled = false         
        }
        if(obj == "Select_fwq")
        {
            $(obj).disabled = false
            $(obj).style.backgroundColor = "#FFFFFF"
            $("button_query").disabled = false      
        }
        if(obj == "Text_czsj")
        {
            $("Text_qsrq").disabled = false  
            $("Text_qsrq").style.backgroundColor = "#FFFFFF" 
            $("Text_zzrq").disabled = false  
            $("Text_zzrq").style.backgroundColor = "#FFFFFF" 
            $("button_query").disabled = false 
        }
        else
        {
            $(obj).disabled = false          
            $(obj).style.backgroundColor = "#FFFFFF"   
            $("button_query").disabled = false 
        }
    }
    else
    {
        if(obj == "Select_jb")
        {
            $(obj).disabled = true 
            $(obj).style.backgroundColor = "#F5F5F5"
            $("Text_jb").disabled = true
            $("Text_jb").value = ""
            $("Text_jb").style.backgroundColor = "#F5F5F5"            
        }
        if(obj == "Select_fwq")
        {
            $(obj).disabled = true 
            $(obj).style.backgroundColor = "#F5F5F5"
        }
        if(obj == "Text_czsj")
        {
            $("Text_qsrq").disabled = true
            $("Text_qsrq").value = ""
            $("Text_qsrq").style.backgroundColor = "#F5F5F5" 
            $("Text_zzrq").disabled = true
            $("Text_zzrq").value = ""
            $("Text_zzrq").style.backgroundColor = "#F5F5F5"   
        }
        else
        {
            $(obj).disabled = true
            $(obj).value = ""
            $(obj).style.backgroundColor = "#F5F5F5"
        }
    }
}

function onRowClick(evt, rowno)
{
    var rowobj = vList.getRow(rowno);
    id0 = rowobj.getCell("id0");
    addrid0 = rowobj.getCell("addrid0");
}


function AttView()
{
    major = 95;
    minor = 864;
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'view', null])
}

function AddrLoct()
{
    major = 95;
    minor = 540;
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_LOC, [major, minor, addrid0.text])
}

function AddrQuery_onclick()
{
    var ischeck = 0;
    //服务区CheckBox被选中
    if($("Check_fwq").checked)
    {
        strsql = "AREAID ='" + $("Select_fwq").value + "'";
        ischeck = 1;
    }
    //地址中文CheckBox被选中
    if($("Check_dzzw").checked)
    {
        if(ischeck == 0)
        {
            strsql = "XXDZ like '%" + $("Text_dzzw").value + "%'";
        }
        else
        {
            strsql += " and XXDZ like '%" + $("Text_dzzw").value + "%'";
        }
        ischeck = 1;
    }
    //地址简拼CheckBox被选中
    if($("Check_dzjp").checked)
    {
        if(ischeck == 0)
        {
            strsql = "XXJP like '%" + $("Text_dzjp").value + "%'";
        }
        else
        {
            strsql += " and XXJP like '%" + $("Text_dzjp").value + "%'";
        }
        ischeck = 1;
    }
    //地址级别CheckBox被选中
    if($("Check_jb").checked)
    {
        var vRankVal = GetRankVal($("Select_jb").value)
        if(ischeck == 0)
        {
            strsql = ""+ vRankVal + " in (select ID0 from teaddr where type = '"+$("Select_jb").value+"' and bm like '%"+$("Text_jb").value+"%')"
        }
        else
        {
            strsql += "AND "+ vRankVal + " in (select ID0 from teaddr where type = '"+$("Select_jb").value+"' and bm like '%"+$("Text_jb").value+"%')"
        }
    }
    //操作时间CheckBox被选中
    if($("Check_czsj").checked)
    {
        if($("Text_qsrq").value == "" && $("Text_zzrq").value == "")
        {
            top.CtnDlg.error("请输入查询的起始日期或终止日期!");
            return ;
        }
        if(ischeck == 0)
        {
            //起始时间为空
            if($("Text_qsrq").value == "")
            {
                strsql = "LOGDATE <= to_date('" + $("Text_zzrq").value + "','yyyy-mm-dd hh24:mi:ss')"
            }
            //终止时间为空
            if($("Text_zzrq").value == "")
            {
                strsql = "LOGDATE >= to_date('" + $("Text_qsrq").value + "','yyyy-mm-dd hh24:mi:ss')"
            }
            else 
            {
                strsql = "LOGDATE <= to_date('" + $("Text_zzrq").value + "','yyyy-mm-dd hh24:mi:ss') AND LOGDATE >= to_date('" + $("Text_qsrq").value + "','yyyy-mm-dd hh24:mi:ss')"
            }
        }
        else
        {
            if($("Text_qsrq").value == "")
            {
                strsql += "AND LOGDATE <= to_date('" + $("Text_zzrq").value + "','yyyy-mm-dd hh24:mi:ss')"
            }
            if($("Text_zzrq").value == "")
            {
                strsql += "AND LOGDATE >= to_date('" + $("Text_qsrq").value + "','yyyy-mm-dd hh24:mi:ss')"
            }
            else 
            {
                strsql += "AND LOGDATE <= to_date('" + $("Text_zzrq").value + "','yyyy-mm-dd hh24:mi:ss') AND LOGDATE >= to_date('" + $("Text_qsrq").value + "','yyyy-mm-dd hh24:mi:ss')"
            }
        }
        ischeck = 1
    }
    //Sql为空
    if(strsql == "" || strsql == null)
    {
        top.CtnDlg.error("查询条件为空");
        return ;
    }
    vList.onGoPage(1);
}

function GetRankVal(val)
{
    var vVal
    switch(val)
    {
        case "14":
            vVal = "ADDRID1"
            break;
        case "15":
            vVal = "ADDRID2"
            break;
        case "16":
            vVal = "ADDRID3"
            break;
        case "18":
            vVal = "ADDRID4"
            break;
        case "19":
            vVal = "ADDRID5"
            break;
        default:
            break;       
    }
    return vVal
}


function gotoPage(page)
{
    var vUrl = "_method=getAddrDetail&major=95&minor=864&strsql="+escape(strsql)+"&pageno="+page+"&size="+vList.pagesize
    var vData = CtnTrans.getText("/main.ashx", "post", vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
        return;
    }
    else if(vData == "false")
    {
        CtnDlg.msg("没有符合条件的记录!")
    }
    else
    {
        vList.reset();
        vList.insertXml(vData, 1);
        vList.show();
    }
}